package com.list01.example01;

import java.awt.*;
import java.util.ArrayList;
import java.util.Scanner;

public class StudentManagereDemo2 {
   Scanner  Scanner = new Scanner(System.in);
  ArrayList<Student> studentList = new ArrayList();

    public static void main(String[] args) {
        StudentManagereDemo2 studentManagereDemo2 = new StudentManagereDemo2();
      studentManagereDemo2.init();
    }
    private  void  init(){
        while (true){
            System.out.println("选择(1.录入)");
            System.out.println("(0.退出)");
            int choice = Scanner.nextInt();
            if (choice == 1){
                add();
            } else if (choice == 0) {
                printStudent();
                Scanner.close();
                break;
        }
    }

}
private void printStudent(){
    for (int i = 0; i <studentList.size() ; i++) {
        Student student = studentList.get(i);
        System.out.println(student.getName()+"--------" + student.getAge());

    }
    }
    private void  add(){
        System.out.println("请输入学生的姓名：");
        String name = Scanner.next();
        System.out.println("请输入学生的年龄：");
        int age = Scanner.nextInt();
        Student student = new Student();
        student.setAge(age);
        student.setName(name);
        studentList.add(student);

    }
}

